package net.yambal.android.secretary_alarm.array_adupoter;

import net.yambal.android.secretary_alarm.db.Alarm;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AlarmArrayAdapter extends ArrayAdapter<Alarm> {
	private int _textViewResourceId;
	private Alarm[] _alarms;
	private LayoutInflater _inflater;

	public AlarmArrayAdapter(Context context, int textViewResourceId, Alarm[] alarms) {
		super(context, textViewResourceId, alarms);
		_textViewResourceId = textViewResourceId;
		_alarms = alarms;
		_inflater = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE
		);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		if(convertView == null){
			convertView = _inflater.inflate(_textViewResourceId, null);
		}
		final Alarm alarm = _alarms[position];
		if(alarm != null){
			TextView mTitle = (TextView)convertView.findViewWithTag("textViewAlatmID");
			mTitle.setText(alarm.toString());
		}
		return convertView;
	}
	
	@Override
    public Alarm getItem(int position) {
      return _alarms[position];
    }
	
	@Override
    public int getCount() {
      return _alarms.length;
    }
	
	@Override
    public long getItemId(int position) {
      return position;
    }

}
